package com.qianfeng.openplatform.webmaster.controller;

import com.qianfeng.openplatform.webmaster.entry.LayuiDataTableSource;
import com.qianfeng.openplatform.webmaster.entry.OpenApiMaster;
import com.qianfeng.openplatform.webmaster.pojo.ApiMapping;
import com.qianfeng.openplatform.webmaster.service.ApiMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 江江
 * @Date 2020/7/23 15:27
 */
@RestController
@RequestMapping("/sys/api_mapping")
public class ApiMappingController {

    @Autowired
    private ApiMappingService apiMappingService;

    @RequestMapping("/table")
    public LayuiDataTableSource apiMappingTable(@RequestParam(defaultValue = "1") Integer page,
                                                @RequestParam(defaultValue = "10") Integer limit,
                                                @RequestParam(required = false) String gatewayapiname,
                                                Integer state) {
        //System.out.println(gatewayapiname);
        return apiMappingService.getApiMappingPage(page, limit, gatewayapiname, state);
    }

    @RequestMapping("/update")
    public OpenApiMaster updateMapping(ApiMapping apiMapping) {

        if (apiMapping.getId() !=null){
            return apiMappingService.updateApiMapping(apiMapping);
        }else{
            return apiMappingService.addApiMapping(apiMapping);
        }
    }

    @RequestMapping("/del")
    public OpenApiMaster delMapping(Integer[] ids){
        System.out.println(ids);
        return apiMappingService.delApiMapping(ids);

    }
}
